#include <iostream>
#include <algorithm>

using namespace std;
#define int long long

int n , m , k , x;

int qpow(int a , int b , int q)
{
    int ret = 1;
    while(b)
    {
        if(b & 1) ret = (ret * a) % q;
        b >>= 1;
        a = a * a % q;
    }
    return ret;
}
signed main()
{
    cin >> n >> m >> k >> x;
    cout << (x + m * qpow(10 , k , n)) % n << endl;
    return 0;
}